package com.ym.b2b.buyer.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.buyer.dao.EmCBuyerDao;
import com.ym.b2b.buyer.sqlbean.EmCBuyer;
import com.ym.b2b.buyer.sqlbean.SimpleEmCBuyer;
import com.ym.b2b.commons.dao.BaseDao;
import com.zc.commons.base.Page;

@Repository
public class EmCBuyerDaoImpl<T> extends BaseDao<T> implements EmCBuyerDao {

    @Override
    public Page<EmCBuyer> searchPageEmCBuyer(Page<EmCBuyer> page, EmCBuyer emCBuyer) throws DataAccessException {
        page.setTotalRow(searchPageEmCBuyerNum(emCBuyer));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", emCBuyer);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_C_BUYER.searchPageEmCBuyer", map));
        return page;
    }

    @Override
    public Long searchPageEmCBuyerNum(EmCBuyer emCBuyer) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", emCBuyer);
        return (Long) listNum("EM_C_BUYER.searchPageEmCBuyerNum", map);
    }

    @Override
    public EmCBuyer showEmCBuyerDetail(EmCBuyer emCBuyer) throws DataAccessException {

        return (EmCBuyer) find("EM_C_BUYER.showEmCBuyerDetail", emCBuyer);
    }

    @Override
    public void insertBuyer(EmCBuyer emCBuyer) throws DataAccessException {
        insert("EM_C_BUYER.insertEmCBuyer", emCBuyer);
    }

    @Override
    public void updateBuyer(EmCBuyer emCBuyer) throws DataAccessException {
        update("EM_C_BUYER.updateEmCBuyer", emCBuyer);
    }

    /*
     * @Override public List<EmCBuyer> searchEmCBuyer(EmCBuyer emCBuyer) throws DataAccessException { return null; }
     */

    @Override
    public void deleteEmCBuyer(EmCBuyer emCBuyer) throws DataAccessException {
        delete("EM_C_BUYER.deleteEmCBuyer", emCBuyer);

    }

    /*
     * (non-Javadoc)
     * @see com.ym.b2b.buyer.dao.EmCBuyerDao#editMultipleEmCBuyersStatus(java.lang.String)
     */
    @Override
    public void editMultipleEmCBuyersStatus(String buyerIdList) {
        update("EM_C_BUYER.updateMultipleEmCBuyerStatus", buyerIdList);
    }

    @Override
    public void deleteMultipleEmCBuyers(String buyerIdList) {
        delete("EM_C_BUYER.deleteMultipleEmCBuyers", buyerIdList);
    }

    @Override
    public SimpleEmCBuyer showSimpleEmCBuyerDetail(EmCBuyer emCBuyer) throws DataAccessException {
        return (SimpleEmCBuyer) find("EM_C_BUYER.showSimpleEmCBuyerDetail", emCBuyer);
    }
}
